package com.etime.shycourse.controller.wx.applets.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shy.common.ListMessage;
import com.etime.shycourse.config.PageMessage;
import com.etime.shycourse.pojo.Course;
import com.etime.shycourse.pojo.Coursetype;
import com.etime.shycourse.services.interfaces.WxCourseServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wb
 * @since 2021-12-17
 */

@Api(tags = "微信课程数据接口")
@RestController
@RequestMapping("/wx/course")
public class WxCourseController {
    @Autowired
    private WxCourseServices service;

    @ApiOperation("精品推荐 recommended数据接口")
    @GetMapping("/recommended/list")
    public ListMessage<Course> selectCourseListByIds() {
        ListMessage<Course> msg = new ListMessage<> ();
        List<Course> data = service.selectCourseRecommended ();
        if (data != null) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有精品推荐的数据");
        }
        return msg;
    }

    @ApiOperation("课程推荐 取课程前10条记录")
    @GetMapping("/recommendation/list")
    public ListMessage<Course> selectCourseRecommendations() {
        ListMessage<Course> msg = new ListMessage<> ();
        List<Course> data = service.selectCourseRecommendation ();
        if (data != null) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有课程推荐的数据");
        }
        return msg;
    }

    @ApiOperation("初始化课程列表显示 课程的分类")
    @GetMapping("/CourseTypeSort/list")
    public ListMessage<Coursetype> selectCourseTypAll() {
        ListMessage<Coursetype> msg = new ListMessage<> ();
        List<Coursetype> data = service.selectCourseTypAll ();
        if (data != null) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有课程分类的数据");
        }
        return msg;
    }

    @ApiOperation("微信课程分页查询列表 可用：显示“全部”的课程、课程列表显示、课程搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "没有加中文的可不填", value = "注意中文注解"),
            @ApiImplicitParam(name = "pagenum", value = "第几页 可不传(显示“全部”的课程时)"),
            @ApiImplicitParam(name = "pagesize", value = "每页多少行 可不传(显示“全部”的课程时)"),
            // 复用
            @ApiImplicitParam(name = "coursetypeid", value = "非必要条件 课程列表显示（或者课程搜索）用户在课程大类型情况下进行课程列表显示（或者课程名搜索） coursetypeid "),
            // 复用
            @ApiImplicitParam(name = "coursetitle", value = "非必要条件 课程搜索模糊查询 课程名 coursetitle"),
    })
    @GetMapping("/page")
    public PageMessage<Course> selectCoursePageBy(Course course, Long pagenum, Long pagesize) {
        PageMessage<Course> msg = new PageMessage<> ();
        Page<Course> data = service.selectCoursePageBy (course, pagenum, pagesize);
        if (data != null) {
            msg.setCode (1);
            msg.setPagedata (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有查询到数据");
        }
        return msg;
    }
}
